{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "from keras import activations\n",
    "from keras import backend as K\n",
    "import json\n",
    "from collections import OrderedDict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def format_decimal(arr):\n",
    "    return [round(x * 1e6) / 1e6 for x in arr]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "DATA = OrderedDict()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### softmax"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.softmax.0] 1D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 2]\n",
      "in shape: (6,)\n",
      "out shape: (6,)\n",
      "out: [0.067194, 0.082071, 0.110784, 0.0608, 0.182652, 0.4965]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 2]\n",
    "data_in_shape = (6,)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.softmax(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.softmax.0'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                                 'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.softmax.1] 2D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 6)\n",
      "out shape: (2, 6)\n",
      "out: [0.067194, 0.082071, 0.110784, 0.0608, 0.182652, 0.4965, 0.107768, 0.149902, 0.11105, 0.247147, 0.082268, 0.301865]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 6)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.softmax(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.softmax.1'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                                 'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.softmax.2] 1D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 90]\n",
      "in shape: (6,)\n",
      "out shape: (6,)\n",
      "out: [0.0, 0.0, 0.0, 0.0, 0.0, 1.0]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 90]\n",
    "data_in_shape = (6,)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.softmax(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.softmax.2'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                                 'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### elu"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.elu.0] 1D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 2]\n",
      "in shape: (6,)\n",
      "out shape: (6,)\n",
      "out: [0.0, 0.2, 0.5, -0.095163, 1.0, 2.0]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 2]\n",
    "data_in_shape = (6,)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.elu(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.elu.0'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                             'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.elu.1] 2D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 6)\n",
      "out shape: (2, 6)\n",
      "out: [0.0, 0.2, 0.5, -0.095163, 1.0, 2.0, -0.029555, 0.3, 0.0, 0.8, -0.259182, 1.0]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 6)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.elu(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.elu.1'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                             'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.elu.2] 3D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 2, 3)\n",
      "out shape: (2, 2, 3)\n",
      "out: [0.0, 0.2, -0.393469, -0.095163, 1.0, 2.0, -0.029555, 2.3, 0.0, 0.8, -0.259182, 1.0]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 2, 3)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.elu(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.elu.2'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                             'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.elu.3] 3D, alpha=0.5**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 2, 3)\n",
      "out shape: (2, 2, 3)\n",
      "out: [0.0, 0.2, -0.196735, -0.047581, 1.0, 2.0, -0.014777, 2.3, 0.0, 0.8, -0.129591, 1.0]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 2, 3)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.elu(K.variable(np.array([arr_in])), alpha=0.5)\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.elu.3'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                             'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### selu"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.selu.0] 1D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 2]\n",
      "in shape: (6,)\n",
      "out shape: (6,)\n",
      "out: [0.0, 0.21014, 0.525351, -0.167305, 1.050701, 2.101402]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 2]\n",
    "data_in_shape = (6,)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.selu(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.selu.0'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                              'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.selu.1] 2D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 6)\n",
      "out shape: (2, 6)\n",
      "out: [0.0, 0.21014, 0.525351, -0.167305, 1.050701, 2.101402, -0.05196, 0.31521, 0.0, 0.840561, -0.455667, 1.050701]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 6)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.selu(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.selu.1'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                              'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.selu.2] 3D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 2, 3)\n",
      "out shape: (2, 2, 3)\n",
      "out: [0.0, 0.21014, -0.691758, -0.167305, 1.050701, 2.101402, -0.05196, 2.416612, 0.0, 0.840561, -0.455667, 1.050701]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 2, 3)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.selu(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.selu.2'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                              'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### softplus"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.softplus.0] 1D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 2]\n",
      "in shape: (6,)\n",
      "out shape: (6,)\n",
      "out: [0.693147, 0.798139, 0.974077, 0.644397, 1.313262, 2.126928]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 2]\n",
    "data_in_shape = (6,)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.softplus(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.softplus.0'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                                  'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.softplus.1] 2D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 6)\n",
      "out shape: (2, 6)\n",
      "out: [0.693147, 0.798139, 0.974077, 0.644397, 1.313262, 2.126928, 0.67826, 0.854355, 0.693147, 1.171101, 0.554355, 1.313262]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 6)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.softplus(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.softplus.1'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                                  'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.softplus.2] 3D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 2, 3)\n",
      "out shape: (2, 2, 3)\n",
      "out: [0.693147, 0.798139, 0.474077, 0.644397, 1.313262, 2.126928, 0.67826, 2.395545, 0.693147, 1.171101, 0.554355, 1.313262]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 2, 3)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.softplus(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.softplus.2'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                                  'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### softsign"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.softsign.0] 1D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 2]\n",
      "in shape: (6,)\n",
      "out shape: (6,)\n",
      "out: [0.0, 0.166667, 0.333333, -0.090909, 0.5, 0.666667]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 2]\n",
    "data_in_shape = (6,)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.softsign(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.softsign.0'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                                  'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.softsign.1] 2D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 6)\n",
      "out shape: (2, 6)\n",
      "out: [0.0, 0.166667, 0.333333, -0.090909, 0.5, 0.666667, -0.029126, 0.230769, 0.0, 0.444444, -0.230769, 0.5]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 6)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.softsign(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.softsign.1'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                                  'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.softsign.2] 3D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 2, 3)\n",
      "out shape: (2, 2, 3)\n",
      "out: [0.0, 0.166667, -0.333333, -0.090909, 0.5, 0.666667, -0.029126, 0.69697, 0.0, 0.444444, -0.230769, 0.5]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 2, 3)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.softsign(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.softsign.2'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                                  'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ReLU"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.relu.0] 1D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 2]\n",
      "in shape: (6,)\n",
      "out shape: (6,)\n",
      "out: [0.0, 0.2, 0.5, 0.0, 1.0, 2.0]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 2]\n",
    "data_in_shape = (6,)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.relu(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.relu.0'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                              'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.relu.1] 2D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 6)\n",
      "out shape: (2, 6)\n",
      "out: [0.0, 0.2, 0.5, 0.0, 1.0, 2.0, 0.0, 0.3, 0.0, 0.8, 0.0, 1.0]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 6)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.relu(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.relu.1'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                              'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.relu.2] 3D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 2, 3)\n",
      "out shape: (2, 2, 3)\n",
      "out: [0.0, 0.2, 0.0, 0.0, 1.0, 2.0, 0.0, 2.3, 0.0, 0.8, 0.0, 1.0]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 2, 3)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.relu(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.relu.2'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                              'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.relu.3] 3D, max_value=0.5**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 2, 3)\n",
      "out shape: (2, 2, 3)\n",
      "out: [0.0, 0.2, 0.0, 0.0, 0.5, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 2, 3)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.relu(K.variable(np.array([arr_in])), max_value=0.5)\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.relu.3'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                              'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.relu.4] 3D, alpha=0.3**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 2, 3)\n",
      "out shape: (2, 2, 3)\n",
      "out: [0.0, 0.2, -0.15, -0.03, 1.0, 2.0, -0.009, 2.3, 0.0, 0.8, -0.09, 1.0]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 2, 3)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.relu(K.variable(np.array([arr_in])), alpha=0.3)\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.relu.4'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                              'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### tanh"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.tanh.0] 1D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 2]\n",
      "in shape: (6,)\n",
      "out shape: (6,)\n",
      "out: [0.0, 0.197375, 0.462117, -0.099668, 0.761594, 0.964028]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 2]\n",
    "data_in_shape = (6,)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.tanh(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.tanh.0'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                              'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.tanh.1] 2D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 6)\n",
      "out shape: (2, 6)\n",
      "out: [0.0, 0.197375, 0.462117, -0.099668, 0.761594, 0.964028, -0.029991, 0.291313, 0.0, 0.664037, -0.291313, 0.761594]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 6)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.tanh(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.tanh.1'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                              'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.tanh.2] 3D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 2, 3)\n",
      "out shape: (2, 2, 3)\n",
      "out: [0.0, 0.197375, -0.462117, -0.099668, 0.761594, 0.964028, -0.029991, 0.980096, 0.0, 0.664037, -0.291313, 0.761594]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 2, 3)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.tanh(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.tanh.2'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                              'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### sigmoid"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.sigmoid.0] 1D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 2]\n",
      "in shape: (6,)\n",
      "out shape: (6,)\n",
      "out: [0.5, 0.549834, 0.622459, 0.475021, 0.731059, 0.880797]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 2]\n",
    "data_in_shape = (6,)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.sigmoid(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.sigmoid.0'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                                 'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.sigmoid.1] 2D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 6)\n",
      "out shape: (2, 6)\n",
      "out: [0.5, 0.549834, 0.622459, 0.475021, 0.731059, 0.880797, 0.492501, 0.574443, 0.5, 0.689974, 0.425557, 0.731059]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 6)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.sigmoid(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.sigmoid.1'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                                 'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.sigmoid.2] 3D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 2, 3)\n",
      "out shape: (2, 2, 3)\n",
      "out: [0.5, 0.549834, 0.377541, 0.475021, 0.731059, 0.880797, 0.492501, 0.908877, 0.5, 0.689974, 0.425557, 0.731059]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 2, 3)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.sigmoid(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.sigmoid.2'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                                 'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### hard_sigmoid"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.hard_sigmoid.0] 1D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 2]\n",
      "in shape: (6,)\n",
      "out shape: (6,)\n",
      "out: [0.5, 0.54, 0.6, 0.48, 0.7, 0.9]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 2]\n",
    "data_in_shape = (6,)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.hard_sigmoid(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.hard_sigmoid.0'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                                      'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.hard_sigmoid.1] 2D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 6)\n",
      "out shape: (2, 6)\n",
      "out: [0.5, 0.54, 0.6, 0.48, 0.7, 0.9, 0.494, 0.56, 0.5, 0.66, 0.44, 0.7]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 6)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.hard_sigmoid(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.hard_sigmoid.1'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                                      'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.hard_sigmoid.2] 3D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 2, 3)\n",
      "out shape: (2, 2, 3)\n",
      "out: [0.5, 0.54, 0.4, 0.48, 0.7, 0.9, 0.494, 0.96, 0.5, 0.66, 0.44, 0.7]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 2, 3)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.hard_sigmoid(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.hard_sigmoid.2'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                                      'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### linear"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.linear.0] 1D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 2]\n",
      "in shape: (6,)\n",
      "out shape: (6,)\n",
      "out: [0.0, 0.2, 0.5, -0.1, 1.0, 2.0]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 2]\n",
    "data_in_shape = (6,)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.linear(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.linear.0'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                                'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.linear.1] 2D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 6)\n",
      "out shape: (2, 6)\n",
      "out: [0.0, 0.2, 0.5, -0.1, 1.0, 2.0, -0.03, 0.3, 0.0, 0.8, -0.3, 1.0]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 6)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.linear(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.linear.1'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                                'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[activations.linear.2] 3D**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in: [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
      "in shape: (2, 2, 3)\n",
      "out shape: (2, 2, 3)\n",
      "out: [0.0, 0.2, -0.5, -0.1, 1.0, 2.0, -0.03, 2.3, 0.0, 0.8, -0.3, 1.0]\n"
     ]
    }
   ],
   "source": [
    "data_in = [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1]\n",
    "data_in_shape = (2, 2, 3)\n",
    "print('in:', data_in)\n",
    "print('in shape:', data_in_shape)\n",
    "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n",
    "\n",
    "result = activations.linear(K.variable(np.array([arr_in])))\n",
    "\n",
    "arr_out = K.eval(result)[0]\n",
    "data_out_shape = arr_out.shape\n",
    "print('out shape:', data_out_shape)\n",
    "data_out = format_decimal(arr_out.ravel().tolist())\n",
    "print('out:', data_out)\n",
    "\n",
    "DATA['activations.linear.2'] = {'input': {'data': data_in, 'shape': data_in_shape},\n",
    "                                'expected': {'data': data_out, 'shape': data_out_shape}}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "### export for Keras.js tests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "filename = '../test/data/activations.json'\n",
    "if not os.path.exists(os.path.dirname(filename)):\n",
    "    os.makedirs(os.path.dirname(filename))\n",
    "with open(filename, 'w') as f:\n",
    "    json.dump(DATA, f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"activations.softmax.0\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 2], \"shape\": [6]}, \"expected\": {\"data\": [0.067194, 0.082071, 0.110784, 0.0608, 0.182652, 0.4965], \"shape\": [6]}}, \"activations.softmax.1\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], \"shape\": [2, 6]}, \"expected\": {\"data\": [0.067194, 0.082071, 0.110784, 0.0608, 0.182652, 0.4965, 0.107768, 0.149902, 0.11105, 0.247147, 0.082268, 0.301865], \"shape\": [2, 6]}}, \"activations.softmax.2\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 90], \"shape\": [6]}, \"expected\": {\"data\": [0.0, 0.0, 0.0, 0.0, 0.0, 1.0], \"shape\": [6]}}, \"activations.elu.0\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 2], \"shape\": [6]}, \"expected\": {\"data\": [0.0, 0.2, 0.5, -0.095163, 1.0, 2.0], \"shape\": [6]}}, \"activations.elu.1\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], \"shape\": [2, 6]}, \"expected\": {\"data\": [0.0, 0.2, 0.5, -0.095163, 1.0, 2.0, -0.029555, 0.3, 0.0, 0.8, -0.259182, 1.0], \"shape\": [2, 6]}}, \"activations.elu.2\": {\"input\": {\"data\": [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], \"shape\": [2, 2, 3]}, \"expected\": {\"data\": [0.0, 0.2, -0.393469, -0.095163, 1.0, 2.0, -0.029555, 2.3, 0.0, 0.8, -0.259182, 1.0], \"shape\": [2, 2, 3]}}, \"activations.elu.3\": {\"input\": {\"data\": [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], \"shape\": [2, 2, 3]}, \"expected\": {\"data\": [0.0, 0.2, -0.196735, -0.047581, 1.0, 2.0, -0.014777, 2.3, 0.0, 0.8, -0.129591, 1.0], \"shape\": [2, 2, 3]}}, \"activations.selu.0\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 2], \"shape\": [6]}, \"expected\": {\"data\": [0.0, 0.21014, 0.525351, -0.167305, 1.050701, 2.101402], \"shape\": [6]}}, \"activations.selu.1\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], \"shape\": [2, 6]}, \"expected\": {\"data\": [0.0, 0.21014, 0.525351, -0.167305, 1.050701, 2.101402, -0.05196, 0.31521, 0.0, 0.840561, -0.455667, 1.050701], \"shape\": [2, 6]}}, \"activations.selu.2\": {\"input\": {\"data\": [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], \"shape\": [2, 2, 3]}, \"expected\": {\"data\": [0.0, 0.21014, -0.691758, -0.167305, 1.050701, 2.101402, -0.05196, 2.416612, 0.0, 0.840561, -0.455667, 1.050701], \"shape\": [2, 2, 3]}}, \"activations.softplus.0\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 2], \"shape\": [6]}, \"expected\": {\"data\": [0.693147, 0.798139, 0.974077, 0.644397, 1.313262, 2.126928], \"shape\": [6]}}, \"activations.softplus.1\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], \"shape\": [2, 6]}, \"expected\": {\"data\": [0.693147, 0.798139, 0.974077, 0.644397, 1.313262, 2.126928, 0.67826, 0.854355, 0.693147, 1.171101, 0.554355, 1.313262], \"shape\": [2, 6]}}, \"activations.softplus.2\": {\"input\": {\"data\": [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], \"shape\": [2, 2, 3]}, \"expected\": {\"data\": [0.693147, 0.798139, 0.474077, 0.644397, 1.313262, 2.126928, 0.67826, 2.395545, 0.693147, 1.171101, 0.554355, 1.313262], \"shape\": [2, 2, 3]}}, \"activations.softsign.0\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 2], \"shape\": [6]}, \"expected\": {\"data\": [0.0, 0.166667, 0.333333, -0.090909, 0.5, 0.666667], \"shape\": [6]}}, \"activations.softsign.1\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], \"shape\": [2, 6]}, \"expected\": {\"data\": [0.0, 0.166667, 0.333333, -0.090909, 0.5, 0.666667, -0.029126, 0.230769, 0.0, 0.444444, -0.230769, 0.5], \"shape\": [2, 6]}}, \"activations.softsign.2\": {\"input\": {\"data\": [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], \"shape\": [2, 2, 3]}, \"expected\": {\"data\": [0.0, 0.166667, -0.333333, -0.090909, 0.5, 0.666667, -0.029126, 0.69697, 0.0, 0.444444, -0.230769, 0.5], \"shape\": [2, 2, 3]}}, \"activations.relu.0\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 2], \"shape\": [6]}, \"expected\": {\"data\": [0.0, 0.2, 0.5, 0.0, 1.0, 2.0], \"shape\": [6]}}, \"activations.relu.1\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], \"shape\": [2, 6]}, \"expected\": {\"data\": [0.0, 0.2, 0.5, 0.0, 1.0, 2.0, 0.0, 0.3, 0.0, 0.8, 0.0, 1.0], \"shape\": [2, 6]}}, \"activations.relu.2\": {\"input\": {\"data\": [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], \"shape\": [2, 2, 3]}, \"expected\": {\"data\": [0.0, 0.2, 0.0, 0.0, 1.0, 2.0, 0.0, 2.3, 0.0, 0.8, 0.0, 1.0], \"shape\": [2, 2, 3]}}, \"activations.relu.3\": {\"input\": {\"data\": [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], \"shape\": [2, 2, 3]}, \"expected\": {\"data\": [0.0, 0.2, 0.0, 0.0, 0.5, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5], \"shape\": [2, 2, 3]}}, \"activations.relu.4\": {\"input\": {\"data\": [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], \"shape\": [2, 2, 3]}, \"expected\": {\"data\": [0.0, 0.2, -0.15, -0.03, 1.0, 2.0, -0.009, 2.3, 0.0, 0.8, -0.09, 1.0], \"shape\": [2, 2, 3]}}, \"activations.tanh.0\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 2], \"shape\": [6]}, \"expected\": {\"data\": [0.0, 0.197375, 0.462117, -0.099668, 0.761594, 0.964028], \"shape\": [6]}}, \"activations.tanh.1\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], \"shape\": [2, 6]}, \"expected\": {\"data\": [0.0, 0.197375, 0.462117, -0.099668, 0.761594, 0.964028, -0.029991, 0.291313, 0.0, 0.664037, -0.291313, 0.761594], \"shape\": [2, 6]}}, \"activations.tanh.2\": {\"input\": {\"data\": [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], \"shape\": [2, 2, 3]}, \"expected\": {\"data\": [0.0, 0.197375, -0.462117, -0.099668, 0.761594, 0.964028, -0.029991, 0.980096, 0.0, 0.664037, -0.291313, 0.761594], \"shape\": [2, 2, 3]}}, \"activations.sigmoid.0\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 2], \"shape\": [6]}, \"expected\": {\"data\": [0.5, 0.549834, 0.622459, 0.475021, 0.731059, 0.880797], \"shape\": [6]}}, \"activations.sigmoid.1\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], \"shape\": [2, 6]}, \"expected\": {\"data\": [0.5, 0.549834, 0.622459, 0.475021, 0.731059, 0.880797, 0.492501, 0.574443, 0.5, 0.689974, 0.425557, 0.731059], \"shape\": [2, 6]}}, \"activations.sigmoid.2\": {\"input\": {\"data\": [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], \"shape\": [2, 2, 3]}, \"expected\": {\"data\": [0.5, 0.549834, 0.377541, 0.475021, 0.731059, 0.880797, 0.492501, 0.908877, 0.5, 0.689974, 0.425557, 0.731059], \"shape\": [2, 2, 3]}}, \"activations.hard_sigmoid.0\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 2], \"shape\": [6]}, \"expected\": {\"data\": [0.5, 0.54, 0.6, 0.48, 0.7, 0.9], \"shape\": [6]}}, \"activations.hard_sigmoid.1\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], \"shape\": [2, 6]}, \"expected\": {\"data\": [0.5, 0.54, 0.6, 0.48, 0.7, 0.9, 0.494, 0.56, 0.5, 0.66, 0.44, 0.7], \"shape\": [2, 6]}}, \"activations.hard_sigmoid.2\": {\"input\": {\"data\": [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], \"shape\": [2, 2, 3]}, \"expected\": {\"data\": [0.5, 0.54, 0.4, 0.48, 0.7, 0.9, 0.494, 0.96, 0.5, 0.66, 0.44, 0.7], \"shape\": [2, 2, 3]}}, \"activations.linear.0\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 2], \"shape\": [6]}, \"expected\": {\"data\": [0.0, 0.2, 0.5, -0.1, 1.0, 2.0], \"shape\": [6]}}, \"activations.linear.1\": {\"input\": {\"data\": [0, 0.2, 0.5, -0.1, 1, 2, -0.03, 0.3, 0, 0.8, -0.3, 1], \"shape\": [2, 6]}, \"expected\": {\"data\": [0.0, 0.2, 0.5, -0.1, 1.0, 2.0, -0.03, 0.3, 0.0, 0.8, -0.3, 1.0], \"shape\": [2, 6]}}, \"activations.linear.2\": {\"input\": {\"data\": [0, 0.2, -0.5, -0.1, 1, 2, -0.03, 2.3, 0, 0.8, -0.3, 1], \"shape\": [2, 2, 3]}, \"expected\": {\"data\": [0.0, 0.2, -0.5, -0.1, 1.0, 2.0, -0.03, 2.3, 0.0, 0.8, -0.3, 1.0], \"shape\": [2, 2, 3]}}}\n"
     ]
    }
   ],
   "source": [
    "print(json.dumps(DATA))"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
